package com.zr.disruptor;

import com.zr.domain.bar.entity.MarketDataEvent;
import com.zr.domain.bar.service.KLineCalculationService;
import com.zr.disruptor.impl.DisruptorQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
@Order(2)
public class TestDemo implements CommandLineRunner {
    @Autowired
    private DisruptorQueue disruptorQueue;

    @Autowired
    private KLineCalculationService kLineCalculationService;

    @Override
    public void run(String... args) throws Exception {
        kLineCalculationService.calBar();
        for (int i = 0; i < 10; i++) {
            ((Runnable) () -> {
                MarketDataEvent transactionEvent = new MarketDataEvent();
                Random random = new Random();
                for (int j = 0; j < 100; j++) {
                    transactionEvent.setOpen(1);
                    transactionEvent.setLow(2);
                    transactionEvent.setClose(Double.valueOf(random.nextInt(1000) + "." + random.nextInt(100)));
                    transactionEvent.setHigh(random.nextInt(10));
                    disruptorQueue.offer(transactionEvent);
                }
            }).run();
        }

    }
}
